package com.sun.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sun.listener.event.MyEvent;
import com.sun.mapper.StudentMapper;
import com.sun.pojo.Student;
import com.sun.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public Student queryStudentById(Integer id) {
        QueryWrapper<Student>  wrapper = new QueryWrapper<>();
        wrapper.eq("id",id);
        Student student = studentMapper.selectOne(wrapper);
        return student;
    }

    @Override
    public Student getStudentByRedis(String key) {
        Student student = (Student) redisTemplate.opsForValue().get(key);
        return student;
    }

    @Override
    public Student eventGetStudent() {
        QueryWrapper<Student>  wrapper = new QueryWrapper<>();
        wrapper.eq("id",2);
        Student student = studentMapper.selectOne(wrapper);
        MyEvent event = new MyEvent(this,student);

        return student;
    }
}
